package com.ls.markt.controller.superLeague;

import com.ls.markt.model.admin.Player;
import com.ls.markt.service.admin.PlayerService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/clubDetail")
public class ClubDetailController {

    @Resource
    PlayerService playerService;

    /**
     * 跳转到俱乐部详情页
     * @return
     */
    @GetMapping("/{clubId}")
    public ModelAndView detail(@PathVariable("clubId")Long clubId, Model model){
        List<Player> playerList = playerService.listPlayersByClubId(clubId);
//        if (players.size()>0){
//            for (Player player:players){
//                JSONObject playerJson = (JSONObject)JSONObject.toJSON(player);
//                playerJson.put("clubName",clubService.getClubName(player.getClub()));
//            }
//        }
//        model.addAttribute("clubId",clubId);
        model.addAttribute("playerList",playerList);
        return new ModelAndView("superLeague/clubDetail","clublModel",model);
    }

}
